package com.traffic.between.adaptor;

import java.util.Date;
import org.apache.log4j.Logger;
import com.traffic.between.annotation.ChooseProvider;
import com.traffic.between.config.OrderInfoContext;
import com.traffic.between.redis.running.BsmOrderResultExecutor;
import com.traffic.between.service.JieXunServiceImpl;
import com.traffic.managent.service.order.bean.OrderBean;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@ChooseProvider(channel = "jiexun")
public class JieXunAdaptor implements IAdaptor{

	private static Logger log = Logger.getLogger(JieXunAdaptor.class);

	public void order() {
		
		OrderBean orderBean = OrderInfoContext.getContext();
		orderBean.setSendTime(new Date());
		String servicecode = orderBean.getProductCode();
		String telecode = orderBean.getPhoneNo();
		String orderNo = orderBean.getIds();
		
		String result = JieXunServiceImpl.service.order(servicecode, telecode, orderNo);
		log.info("between- 杰讯联合订单JieXunService.order() 订购响应response<>:" + result);

		JSONArray jsonArray = JSONArray.fromObject(result);
		JSONObject json = (JSONObject) jsonArray.get(0);

		String code = json.getString("status");// 只有两个状态 成功或失败 该上游是直充的

		if ("success".equals(code)) {
			orderBean.setStatus("7");
			orderBean.setMessage("充值成功");
			orderBean.setErrorMsg("充值成功");
		} else {
			orderBean.setStatus("8");
			orderBean.setMessage("订购失败");
			orderBean.setErrorMsg("订购失败");
		}

		BsmOrderResultExecutor.service.setOrder(orderBean);
	}

	
}
